﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SensorNetworkUI;
namespace WebAccess
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["username"] = null;

        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            try
            {
                UserDataStructure refe = new UserDataStructure(loginname.Text);
                refe = Global.users.Lookup(loginname.Text);

                if (refe.Password.Equals(pass.Text))
                {

                    Session["username"] = refe;

                    refe.GetNetworks();
                    refe.PopulateNetworks();
                    Response.Redirect("~/start.aspx");


                }
                else
                {

                    CustomValidator1.ErrorMessage = "Password Mismatch";
                }


            }
            catch (UserNotFoundException)
            {
                CustomValidator1.ErrorMessage = "Invalid Username";
                CustomValidator1.IsValid = false;


            }



        }
    }
}